package com.list.model.measure;

import java.util.Enumeration;
import java.util.Vector;

public class MathFunction {
	public static double log2(double a) {
        return (Math.log(a) / Math.log((double)2));
    }

    public static double sigmoid(double t, double move, double slope) {
        return 1 / (1 + Math.exp(-(slope * (t - move))));
    }

    public static double average(Enumeration<Double> values) {
        int count = 0;
        double sum = 0.0;
        while(values.hasMoreElements()) {
            count++;
            sum += values.nextElement();
        }
        return (sum / (double)count);
    }

    public static double average(Vector<Double> values) {
        int count = 0;
        double sum = 0.0;
        for(; count < values.size(); count++) {
            sum += values.get(count);
        }
        return (sum / (double)count);
    }

    public static double deviation(Enumeration<Double> values, Double average) {
        int count = 0;
        double sum = 0.0;
        while(values.hasMoreElements()) {
            count++;
            sum += Math.pow((values.nextElement() - average), 2);
        }
        return Math.sqrt(sum / (double)count);
    }

    public static double deviation(Vector<Double> values, Double average) {
        int count = 0;
        double sum = 0.0;
        for(; count < values.size(); count++) {
            sum += Math.pow((values.get(count) - average), 2);
        }
        return Math.sqrt(sum / (double)count);
    }
}
